package com.fattyCorps.common.packet.hero.component.skill.component;

import com.fattyCorps.common.obj.config.SkillGroupMould;
import com.fattyCorps.common.obj.config.SkillMould;
import com.fattyCorps.common.util.GameCfgUtils;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

public class BirthSkill extends ABaseSkillComponent {
    @Getter
    private List<SkillMould> skills = new ArrayList<>();

    @Override
    public void onInit() {

    }

    @Override
    public void onUpdate() {
        // 根据等级和星级更新技能
        updateSkills();
    }

    @Override
    public void onEvent(int e, Object[] objs) {

    }

    public void updateSkills() {
        skills.clear();

        // 根据星级解锁
        for (Integer skillGroupId : heroMould.getSkillGroupIdsList()) {
            // 一组中只有一个最高解锁等级的技能生效
            SkillGroupMould skillGroupMould = cfg.getCfg(SkillGroupMould.class, skillGroupId);
            List<Integer> skillIds = GameCfgUtils.splitIdListStr(skillGroupMould.getSkillIds());
            SkillMould unlockSkill = null;

            for (Integer skillId : skillIds) {
                SkillMould cfgSkill = cfg.getCfg(SkillMould.class, skillId);

                if (hero.getStar() >= cfgSkill.getUnlockStar() && hero.getLv() >= cfgSkill.getUnlockLv()) {
                    if (unlockSkill == null || unlockSkill.getLv() < cfgSkill.getLv()) {
                        unlockSkill = cfgSkill;
                    }
                }
            }

            if (unlockSkill != null) {
                skills.add(unlockSkill);
            }
        }
    }
}
